001 /* 002 * Copyright 2006 Stephen McConnell. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package net.dpml.http; 017 018 /** 019 * Thread pool implementation. 020 * @author <a href="http://www.dpml.net">Digital Product Meta Library</a> 021 * @version 0.0.3 022 */ 023 public class SelectChannelConnector extends org.mortbay.jetty.nio.SelectChannelConnector 024 { 025 private static final int HEADER_BUFFER_SIZE = 4*1024; 026 private static final int REQUEST_BUFFER_SIZE = 8*1024; 027 private static final int RESPONSE_BUFFER_SIZE = 32*1024; 028 private static final int MAXIMUM_IDLE_TIME = 30000; 029 private static final int ACCEPT_QUEUE_SIZE = 0; 030 private static final int ACCEPTORS = 1; 031 private static final int SO_LINGER_TIME = 1000; 032 private static final int CONFIDENTIAL_PORT = 0; 033 private static final int INTEGRAL_PORT = 0; 034 private static final boolean ASSUME_SHORT_DISPATCH = false; 035 036 /** 037 * Select channel context definition. 038 */ 039 public interface Context extends ConnectorContext 040 { 041 /** 042 * Return the policy concerning short dispatch. 043 * @param flag implementation defined default value 044 * @return the supplied policy unless overriden in the deployment configuration 045 */ 046 boolean getDelaySelectKeyUpdate( boolean flag ); 047 } 048 049 /** 050 * Creation of a new <tt>SelectChannelConnector</tt>. 051 * @param context the component context 052 * @exception Exception if a component configuration error occurs 053 */ 054 public SelectChannelConnector( Context context ) throws Exception 055 { 056 super(); 057 058 String host = context.getHost( null ); 059 if( null != host ) 060 { 061 setHost( host ); 062 } 063 064 int port = context.getPort(); 065 setPort( port ); 066 067 int headerBufferSize = context.getHeaderBufferSize( HEADER_BUFFER_SIZE ); 068 setHeaderBufferSize( headerBufferSize ); 069 070 int requestBufferSize = context.getRequestBufferSize( REQUEST_BUFFER_SIZE ); 071 setRequestBufferSize( requestBufferSize ); 072 073 int responseBufferSize = context.getResponseBufferSize( RESPONSE_BUFFER_SIZE ); 074 setResponseBufferSize( responseBufferSize ); 075 076 int maxIdle = context.getMaxIdleTime( MAXIMUM_IDLE_TIME ); 077 setMaxIdleTime( maxIdle ); 078 079 int queueSize = context.getAcceptQueueSize( ACCEPT_QUEUE_SIZE ); 080 setAcceptQueueSize( queueSize ); 081 082 int acceptCount = context.getAcceptors( ACCEPTORS ); 083 setAcceptors( acceptCount ); 084 085 int linger = context.getSoLingerTime( SO_LINGER_TIME ); 086 setSoLingerTime( linger ); 087 088 int confidentialPort = context.getConfidentialPort( CONFIDENTIAL_PORT ); 089 setConfidentialPort( confidentialPort ); 090 091 Scheme confidentialScheme = Scheme.parse( context.getConfidentialScheme( "https" ) ); 092 setConfidentialScheme( confidentialScheme.getName() ); 093 094 int integralPort = context.getIntegralPort( INTEGRAL_PORT ); 095 setIntegralPort( integralPort ); 096 097 Scheme integralScheme = Scheme.parse( context.getIntegralScheme( "https" ) ); 098 setIntegralScheme( integralScheme.getName() ); 099 100 // SelectChannelConnector$Context 101 102 boolean flag = context.getDelaySelectKeyUpdate( ASSUME_SHORT_DISPATCH ); 103 setDelaySelectKeyUpdate( flag ); 104 } 105 }